package com.gibs.peixunapi.dao;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import com.gibs.peixunapi.model.Notice;

@Repository
public interface NoticeDao extends JpaRepository<Notice, Integer>, JpaSpecificationExecutor<Notice> {

	@Query("from Notice where title = ?1")
	List<Notice> find(String name);

	@Query("from Notice where title like ?1")
	List<Notice> findLike(String name);

	@Query(value = "select * from Notice limit ?, ?", nativeQuery = true)
	List<Notice> findPage(Integer offset, Integer size);

	@Query(value = "select * from Notice where title = ? limit ?, ?", nativeQuery = true)
	List<Notice> findPage(String name, Integer offset, Integer size);

	@Query(value = "select * from Notice where title like ? limit ?, ?", nativeQuery = true)
	List<Notice> findPageLike(String name, Integer offset, Integer size);

	@Query(value = "select count(*) from Notice where title = ?", nativeQuery = true)
	Long count(String name);

	@Query(value = "select count(*) from Notice where title like ?", nativeQuery = true)
	Long countLike(String name);
	
	@Query("from Notice order by id asc")
	List<Notice> findAllAsc();
}

